package com.health.adapter;

import com.health.R;
import com.health.tools.SPUtil;
import com.health.viewscontrols.lvyuejl.LvYueListActivity;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * 重点人群adapter
 */
public class FocusGroupGridAdapter extends BaseAdapter {
	private int[] imgs;
	private String[] names;
	private int[] colors;
	private Context mContext;
	private int isYf=0;

	// "孕妇", "儿童", "老年人", "高血压", "糖尿病", "精神疾病", "脑卒中", "冠心病", "返回"
	public FocusGroupGridAdapter(Context mContext) {
		this.mContext = mContext;
		String str_jddwno = SPUtil.getStrjddwno(mContext);
//		if("63".equals(str_jddwno.substring(0,2))){//湟源县
//			imgs = new int[] { R.drawable.focus_yf,
//					R.drawable.focus_et,R.drawable.focus_lnr, R.drawable.focus_gxy,
//					R.drawable.focus_tnb, R.drawable.focus_jsjb, R.drawable.focus_ncz,
//					R.drawable.focus_gxb, R.drawable.fjh,R.drawable.mzf,R.drawable.focus_gxb,
//					R.drawable.mzf, R.drawable.gjy,R.drawable.lfs,R.drawable.zqgy,R.drawable.ybrq};
//		names = new String[] { "孕妇", "儿童", "老年人", "高血压", "糖尿病", "严重精神障碍患者",
//				"脑卒中", "冠心病", "肺结核","慢阻肺","冠心病(广西)","慢阻肺(广西)","关节炎(广西)",
//				"类风湿关节炎(广西)","老年慢性支气管炎(广西)","一般人群(广西)"};
//
//		colors = new int[] { 0xff4680C7, 0xff46B9C7, 0xff67A6CB, 0xff4680C7, 0xff46B9C7, 0xff67A6CB,
//				0xff4680C7, 0xff46B9C7, 0xff46B9C7,0xff46B9C7,0xff46B9C7,0xff46B9C7,0xff46B9C7,
//				0xff46B9C7,0xff46B9C7,0xff46B9C7 };

		imgs = new int[] { R.drawable.focus_yf,
				R.drawable.focus_et,R.drawable.focus_lnr, R.drawable.focus_gxy,
				R.drawable.focus_tnb, R.drawable.focus_jsjb, R.drawable.focus_ncz,
				R.drawable.focus_gxb, R.drawable.fjh,R.drawable.mzf};
		names = new String[] { "孕妇", "儿童", "老年人", "高血压", "糖尿病", "严重精神障碍患者",
				"脑卒中", "冠心病", "肺结核","慢阻肺",};

		colors = new int[] { 0xff4680C7, 0xff46B9C7, 0xff67A6CB, 0xff4680C7, 0xff46B9C7, 0xff67A6CB,
				0xff4680C7, 0xff46B9C7, 0xff46B9C7,0xff46B9C7};
//		}else{//其他
//			imgs = new int[] { R.drawable.focus_yf,
//					R.drawable.focus_et,R.drawable.focus_lnr,
//					R.drawable.focus_gxy,R.drawable.focus_tnb, R.drawable.focus_jsjb,
//					R.drawable.focus_ncz, R.drawable.focus_gxb,
//					R.drawable.fjh,R.drawable.self_back };
//			names = new String[] { "孕妇", "儿童", "老年人", "高血压", "糖尿病", "严重精神障碍患者",
//					"脑卒中", "冠心病", "肺结核","返回"};
//			colors = new int[] { 0xff4680C7, 0xff46B9C7, 0xff67A6CB, 0xff4680C7,
//					0xff46B9C7, 0xff67A6CB, 0xff4680C7, 0xff46B9C7, 0xff46B9C7,
//					0xff67A6CB };
//		}
		//
//		imgs = new int[] { R.drawable.focus_lnr, R.drawable.focus_gxy, R.drawable.focus_tnb,R.drawable.focus_jsjb, R.drawable.self_back};
//		names = new String[] { "老年人", "高血压", "糖尿病" ,"严重精神障碍患者","返回" };
//		colors = new int[] { 0xff4680C7, 0xff46B9C7, 0xff67A6CB, 0xff46B9C7, 0xff4680C7 };//

	}

	@Override
	public int getCount() {
		return imgs.length;
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int position) {

		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder vh;
		if (convertView == null) {
			convertView = LayoutInflater.from(mContext).inflate(R.layout.item_jb, null);
			vh = new ViewHolder();
			int drawableID = imgs[position];
			String name = names[position];
			int color = colors[position];
			if(name.equals("孕妇")){
				isYf++;
			}
			if(isYf == 2){
				drawableID = imgs[9];
				name = names[9];
			}
			findView(vh, convertView, drawableID, name, color);
			convertView.setTag(R.id.TAG_VIEWHOLDER, vh);
		} else
			vh = (ViewHolder) convertView.getTag(R.id.TAG_VIEWHOLDER);

		setData(vh, convertView, position);

		return convertView;
	}

	/**
	 * 赋值
	 *
	 * @param h
	 * @param v
	 * @param position
	 * @author 王婷婷
	 * @date 2015年12月3日 上午10:24:28
	 */
	private void setData(ViewHolder h, View v, int position) {
	}

	private void findView(ViewHolder h, View v, int drawableID, String name, int color) {
		h.img = (ImageView) v.findViewById(R.id.norm_img);
		h.nameText = (TextView) v.findViewById(R.id.norm_name);
		System.out.println("名称11："+name);
		h.img.setImageResource(drawableID);
		h.nameText.setText(name);
	}

	private static class ViewHolder {
		ImageView img;
		TextView nameText;
	}

}
